package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.AgedmallProcessStateMapper;
import org.linlinjava.litemall.db.domain.AgedmallProcessState;
import org.linlinjava.litemall.db.domain.AgedmallProcessStateExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class AgedmallProcessStateService {
    @Resource
    private AgedmallProcessStateMapper agedmallProcessStateMapper;

    public void addProcess(Integer type, Integer typeId, String state) {
        AgedmallProcessState processState = new AgedmallProcessState();
        processState.setType(type);
        processState.setTypeId(typeId);
        processState.setState(state);
        processState.setDeleted(false);
        processState.setAddTime(LocalDateTime.now());
        agedmallProcessStateMapper.insertSelective(processState);
    }

    public List<AgedmallProcessState> getList(Integer type, Integer id) {
        AgedmallProcessStateExample example = new AgedmallProcessStateExample();
        example.createCriteria().andDeletedEqualTo(false)
                .andTypeEqualTo(type)
                .andTypeIdEqualTo(id);
        example.setOrderByClause("add_time desc");
        List<AgedmallProcessState> stateList = agedmallProcessStateMapper.selectByExample(example);
        return stateList;
    }
}
